import { ENUM_DATA_SCOPE } from "@/enum/system.enum";
import { SelectOption } from "@arco-design/web-vue";
import { queryModel } from "../service/model/model";
import { fetchStoreOptions } from "../service/store/store";
import { queryTheme, themeCategoryTree } from "../service/theme/theme";
import { QueryTheme } from "../service/theme/types";

const storeList = ref<any[]>([]);

const lcdThemeCategoryList = ref<QueryTheme[]>([]);
const themeCategoryList = ref<SelectOption[]>([]);
const deviceSizeOption = ref<SelectOption[]>([]);
const fetchStoreData = async (forceUpdate = false) => {
  if (forceUpdate) {
    storeList.value = [];
  }

  if (storeList.value.length === 0) {
    const data = await fetchStoreOptions();
    storeList.value = data.data;
  }
};
const fetchLCDThemeCategory = async (update = false) => {
  const data = await queryTheme({
    pageNum: 1,
    pageSize: 20,
    scope: ENUM_DATA_SCOPE.THIS_SHOP_AND_SHARED
  });

  if (update) {
    lcdThemeCategoryList.value = [];
  }
  if (lcdThemeCategoryList.value.length === 0) {
    lcdThemeCategoryList.value = data.data;
  }
};
const fetchThemeCategory = async (scoped: ENUM_DATA_SCOPE) => {
  const data = await themeCategoryTree(scoped);
  themeCategoryList.value = data.data?.map((v: any) => {
    v.id = v.label;
    return v;
  });
};
/* 获取LCD尺寸列表 */
const fetchDeviceSizeOption = async () => {
  const data = await queryModel();
  deviceSizeOption.value = data.data.map((item: any) => {
    return {
      label: item.description,
      value: item.id
    };
  });
};

export {
  deviceSizeOption,
  fetchDeviceSizeOption,
  fetchLCDThemeCategory,
  fetchStoreData,
  fetchThemeCategory,
  lcdThemeCategoryList,
  storeList,
  themeCategoryList
};
